<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="style.css" />
  <title>注册</title>
</head>
<body>
<div class="container">
  <h1>注册</h1>
  <form>
    <div class="form-control">
      <input id="account" type="text" name="userName" required>
      <label>账号</label>
    </div>

    <div class="form-control">
      <input id="p1" type="password" required>
      <label>密码</label>
    </div>

    <div class="form-control">
      <input id="p2" type="password" required>
      <label>确认密码</label>
    </div>

    <button class="btn">registered</button>

    <p class="text">已有账户? <a href="login.html">登录</a> </p>
  </form>
</div>
<script src="script.js"></script>
<script src="jquery-1.8.3.min.js"></script>
<script>
  $(function (){
    $("form").submit(function (){
      $.ajax({
        type:'POST',
        url:'/searchQueryUsersAccount.action',
        data:'account='+$("#account").val(),
        success:function (resultUser){
          if(resultUser!==""){
            alert("当前账号已被注册，请重新输入");
          }else{
            if($("#p1").val()===$("#p2").val()){
              $.ajax({
                type:'POST',
                url: '/registerAccount.action',
                data: 'loginId='+$('#account').val()+"&password="+$('#p1').val(),
                success:function (resultData){
                  if(resultData>=1){
                    alert("注册成功");
                  }else{
                    alert("注册失败")
                  }
                }
              })
            }else{
              alert("密码不一致");
            }
          }
        }
      });
      return false;
    });
  })
</script>
</body>
</html>
